package net.xdclass.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.xdclass.VO.BannerVO;
import net.xdclass.model.BannerDO;
import net.xdclass.mapper.BannerMapper;
import net.xdclass.service.BannerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author guangyang
 * @since 2023-03-28
 */
@Service
@Slf4j
public class BannerServiceImpl implements BannerService {


    @Autowired
    private BannerMapper bannerMapper;
    @Override
    public List<BannerVO> list() {

        List<BannerDO> bannerDOList = bannerMapper.selectList(new QueryWrapper<BannerDO>().
                orderByDesc("weight"));

        List<BannerVO> bannerVOList = bannerDOList.stream().map(this::invert).collect(Collectors.toList());

        return bannerVOList;
    }

    private BannerVO invert(BannerDO bannerDO){
        BannerVO bannerVO = new BannerVO();
        BeanUtils.copyProperties(bannerDO,bannerVO);
        return bannerVO;
    }
}
